package vg.com.parse;

import java.io.File;
import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;

import vg.com.chatonline.activity.R;

import android.app.Activity;
import android.content.SharedPreferences;
import android.widget.Spinner;

public class spinner extends Activity{

	private static final String PHRASE = "Item_";
	public String prefBody = "PrefBody";
	public String prefCity = "PrefCity";
	public String prefColor = "PrefColor";
	public String prefDrinker = "PrefDrinker";
	public String prefEducation = "PrefEducation";
	public String prefGender = "PrefGender";
	public String prefMaritalStatus = "PrefMaritalStatus";
	public String prefHeight = "PrefHeight";
	public String prefWeight = "PrefWeight";
	public String prefReligion = "PrefReligion";
	public String prefSmoker = "PrefSmoker";
	public String prefUsertype = "PrefUsertype";
	
	
	public String body = "/data/data/com.SlideMenu.chatlove/shared_prefs/PrefBody.xml";
	public String city = "/data/data/com.SlideMenu.chatlove/shared_prefs/PrefCity.xml";
	public String color = "/data/data/com.SlideMenu.chatlove/shared_prefs/PrefColor.xml";
	public String Drinker = "/data/data/com.SlideMenu.chatlove/shared_prefs/PrefDrinker.xml";
	public String education = "/data/data/com.SlideMenu.chatlove/shared_prefs/PrefEducation.xml";
	public String gender = "/data/data/com.SlideMenu.chatlove/shared_prefs/PrefGender.xml";
	public String matital = "/data/data/com.SlideMenu.chatlove/shared_prefs/PrefMaritalStatus.xml";
	public String height = "/data/data/com.SlideMenu.chatlove/shared_prefs/PrefHeight.xml";
	public String weight = "/data/data/com.SlideMenu.chatlove/shared_prefs/PrefWeight.xml";
	public String Religion = "/data/data/com.SlideMenu.chatlove/shared_prefs/PrefReligion.xml";
	public String smoker = "/data/data/com.SlideMenu.chatlove/shared_prefs/PrefSmoker.xml";
	public String Usertype = "/data/data/com.SlideMenu.chatlove/shared_prefs/PrefUsertype.xml";
	
	private JSONParser jparse;
	
	public File f = new File(body);
	public File f1 = new File(city);
	public File f2 = new File(color);
	public File f3 = new File(Drinker);
	public File f4 = new File(education);
	public File f5 = new File(gender);
	public File f6 = new File(matital);
	public File f7 = new File(height);
	public File f8 = new File(weight);
	public File f9 = new File(Religion);
	public File f10 = new File(smoker);
	public File f11 = new File(Usertype);
	public ArrayList<Student> array;
	public MyAdapter adapter;


	public void putPref(String pref, String url) {
		JSONArray jsa = new JSONArray();
		jparse = new JSONParser();
		jsa = jparse.getJsonarray(url);
		SharedPreferences prefs;
		prefs = getSharedPreferences(pref, MODE_PRIVATE);
		SharedPreferences.Editor editor = prefs.edit();
		for (int i = 0; i < jsa.length(); i++) {
			try {
				editor.putString(PHRASE + i + "", jsa.getString(i));
			} catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		editor.commit();
	}
	
	public void dropItems(Spinner sp, String pref, ArrayList<Student> arr) {
		array = new ArrayList<Student>();
		adapter = new MyAdapter(this, R.layout.drop_gender, arr, true);
		sp.setAdapter(adapter);
		SharedPreferences prefs;
		prefs = getSharedPreferences(pref, MODE_PRIVATE);
		for(int i = 0; i < prefs.getAll().size(); i++) {    
            Student n = new Student(prefs.getString(PHRASE + i, ""));
            array.add(n);
        }
		adapter.notifyDataSetChanged();
	}
	
	public ArrayList<Student> dropSpinner(String pref) {
		ArrayList<Student> arrayList=new ArrayList<Student>();
		SharedPreferences prefs;
		prefs = getSharedPreferences(pref, MODE_PRIVATE);
		for(int i = 0; i < prefs.getAll().size(); i++) {    
            Student n = new Student(prefs.getString(PHRASE + i + "", ""));
            arrayList.add(n);
        }
		return arrayList;
	}
}
